package com.sskj.gcc.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.gcc.R;
import com.sskj.gcc.ui.fragment.PayInFragment;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.common.App;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.FabiDetailListBean;
import com.sskj.gocoin.m.bean.PayInInfoBean;
import com.sskj.gocoin.m.bean.PayWayBean;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;

public class PayInFragmentPresenter extends BasePresenter<PayInFragment> {

    public void getPayInfo(){
        OkGo.<HttpData<PayInInfoBean>>get(HttpConfig.BASE_URL + HttpConfig.ONE_BUY)
                .execute(new JsonCallBack<HttpData<PayInInfoBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<PayInInfoBean>> response) {
                        HttpData<PayInInfoBean> httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.onGetPayInfo(httpListData.getData());
                        } else {
                            ToastUtil.showShort(httpListData.getMsg());
                            mView.onGetpayInfoFail(response.body().getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<HttpData<PayInInfoBean>> response) {
                        super.onError(response);
                        mView.onGetpayInfoFail(App.INSTANCE.getString(R.string.one_buy_maintenance));
                    }
                });
    }

    public void withdraw(String num) {
        OkGo.<HttpData<Withdraw>>post(HttpConfig.BASE_URL + HttpConfig.WITHDRAW)
                .params("amount", num)
                .execute(new JsonCallBack<HttpData<Withdraw>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<Withdraw>> response) {
                        if (response.body().getCode() == 200) {
                            mView.getUrlSuccess(response.body().getData().getInfo());
                        }else {
                            ToastUtil.showShort(response.body().getMsg());
                        }
                    }
                });
    }
    public void requsetPayWayList() {
//        OkGo.<HttpData<List<PayWayBean>>>post(HttpConfig.BASE_URL + HttpConfig.PAY_WAY_LIST)
//                .params("account", MyAppLication.getAccount())
//                .execute(new JsonCallBack<HttpData<List<PayWayBean>>>(this, false) {
//
//                    @Override
//                    public void onSuccess(Response<HttpData<List<PayWayBean>>> response) {
//                        mView.onPayWaySuccess(response.body());
//                    }
//                });
    }

    public void requsetCheckSwitch(PayWayBean item) {
//        int status = item.getCode() == 0 ? 1 : 0;
//        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CHANGE_SWITCH)
//                .params("type", item.getType())
//                .params("val", status)
//                .params("account", MyAppLication.getAccount())
//                .execute(new JsonCallBack<HttpData>(this) {
//                    @Override
//                    public void onSuccess(Response<HttpData> response) {
//                        item.setStatus(status);
//                        mView.onChangeSwitchSuccess(item);
//                    }
//                });
    }
}
